define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'reserve_record/index' + location.search,
                    //add_url: 'reserve_setting/add',
                    edit_url: 'reserve_record/edit',
                    //del_url: 'trace_position/del',
                    multi_url: 'reserve_record/multi',
                    table: 'reserve_record',
                }
            });

            var table = $("#table");

            //初始化表格
            // table.bootstrapTable({
            //     url: $.fn.bootstrapTable.defaults.extend.index_url,
            //     pk: 'id',
            //     sortName: 'id',
            //     columns: [
            //         [
            //             // {checkbox: true},
            //             {field: 'id', title: __('ID')},
            //             {field: 'sid', title:__('Sid')},
            //             {field: 'nickname',title:__('Nickname')},
            //             {field: 'add_time_text', title: __('Add_time')},

            //             {field: 'into_time_text', title: __('Into_time')},
            //             {field: 'leave_time_text', title: __('Leave_time')},

            //             {field: 'states_text', title: __('State')},  
            //             // {field: 'abc', title: __('State')},
            //             // {field: 'bbb', title: __('Type')},
            //             //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
            //         ]
            //     ]
            // });
            
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                showExport: true,
                showToggle: false,
                showColumns: false,
                commonSearch: true,
                searchFormVisible: true,                
                searchFormTemplate: 'searchformtpl',
                queryParams: function (params) {
                    //这里可以追加搜索条件
                    var filter = JSON.parse(params.filter);
                    var op = JSON.parse(params.op);
                    if($("#username").val()){
                        filter.username = $("#username").val();
                        op.username = "like";
                    }

                    if($("#sid").val()){
                        filter.sid = $("#sid").val();
                        op.sid = "like";
                    }
                    // if($("#classes_id").val()){
                    //     filter.classes_id = $("#classes_id").val();
                    //     op.classes_id = "=";
                    // }

                    //if($("#is_reported").val()){
                    // filter.add_time = $("#add_time").val();
                    // op.add_time = "between";
                    //}

                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                },
                columns: [
                    [
                        {field: 'id', title: __('ID')},
                        {field: 'sid', title:__('Sid')},
                        {field: 'nickname',title:__('Nickname')},
                        {field: 'add_time_text', title: __('Add_time')},

                        {field: 'into_time_text', title: __('Into_time')},
                        {field: 'leave_time_text', title: __('Leave_time')},

                        {field: 'states_text', title: __('State')},                   
                        // {field: '', title: __('序号'),operate:false,table:table,formatter: Table.api.formatter.natureorder},
                        // {field: 'sid', title: __('Sid'),operate:false},
                        // {field: 'nickname', title: __('Nickname'),operate:false},
                        // {field: 'year_', title: __('Year_')},
                        // {field: 'classes_name', title: __('Classes_name'),addClass: "selectpage", extend: "data-source='classes/index' data-field='name'"},
                        // {field: 'classes_id', title: __('Classes_id'),operate:false,visible:false},
                        // {field: '', title: __('Is_reported'),formatter: function (value, row, index) {
                        //         return "否";
                        //     }},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        // add: function () {
        //     Controller.api.bindevent();
        // },
        // edit: function () {
        //     Controller.api.bindevent();
        // },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});